|
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
Tutorial 2: Programming Beyond Visual Basic
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Working with the API Viewer |
|
| Source | |
Although you do notneed any additional tools in order to work with the Windows API , Visual Basic ships with a tool (the API Viewer) that allows you to cut and paste API functions, constants, and Windows-defined types right into your code. You access the API Viewer from the Visual Basic Start menu. Also, you can add the API Viewer to your VB IDE in the form of an Add-In, thus making it readily available to you while you work.
Simply put, the API allows you to access the DLLs in the Windows environment for programming purposes. Microsoft wisely put all reusable code into DLLs (dynamic link libraries) so that they can be used repeatedly. This not only saves valuable programming time, but also standardizes the programming community by allowing the same code to be used repeatedly. With the same code running in many similar applications, they become more compatible.
In the following sections, you'll build a small program that shows you how to use some API functions to do things you normally can't do in VB. You will use the API Viewer to retrieve functions, constants, and Windows-defined types to help you accomplish this. You will also build a function that reports back the position of the cursor anywhere onscreen. To do this, you need to use the API function GetCursorPos.
To use the API Viewer to retrieve GetCursorPos, you need to configure the viewer for first-time use.
The API Viewer doesn't have API data definition built into it; you must load the data at the beginning of every session. After you configure the API Viewer to read its API definition data from a database file, you select the database file whenever you need to use the API Viewer. Although you can use the provided text file, Win32API.txt, using the database file makes the API Viewer perform faster.
After you configure the API Viewer, you can use it to select functions, constants, and Windows-defined types associated with the Windows API.
Figure 2 You can locate constants, declares(API functions), and types in the API Viewer.
(1) Enables you to filter the available items in terms of constants, declares, or types
(2) Type the item you're looking for in the search text box.
(3) Displays items according to constants, declares, or types. You can scroll through the list, type a few letters in the text box above, or type directly into the list to do a search.
(4) Select whether you want a selected item to be Public or Private in scope
(5) When you find what you want, click to add the item to theSelected Items list
(6) Removes a selected item from the Selected Items list
(7) Clears the Selected Items list of all items
(8) Copies all items in the Selected Itemslist onto the Clipboard for pasting into your project
Figure 3 When you enter a word in the search text box, the API Viewer looks through the available items on a letter-by-letter basis.
Figure 4 The Selected Items list holds selected constants, declares, and types that you can copy to the Clipboard in one process.
Figure 5 You must copy API declarations into the General Declarations section of a module.
Notice that GetCursorPos takes a Windows-defined type, POINTAPI, as an argument. You need to include the type definition in your VB project for the code to work.
|
|
||
|
||||||
|
|||
|
|||
|
| |
| |
| |
|
| |
| |
|
© Copyright 2000 InformIT. All rights reserved. |